/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GUI_BuscarEnfermedad.java
 *
 * Created on 22/10/2011, 02:42:33 PM
 */
package swatsoft3.vista;

import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
import swatsoft3.controlador.*;
import swatsoft3.modelo.*;

/**
 *
 * @author renzo
 */
public class GUI_BuscarEnfermedad extends javax.swing.JDialog {

    private DefaultTableModel modelo;

    /** Creates new form GUI_BuscarEnfermedad */
    public GUI_BuscarEnfermedad(java.awt.Frame parent, boolean modal) {
        super(parent, modal);

        modelo = new DefaultTableModel();
        modelo.addColumn("Artículo"); //Este es el título del artículo
        modelo.addColumn("Oración");
        modelo.addColumn("Tipo");
        modelo.addColumn("Concepto único");

        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel2 = new javax.swing.JLabel();
        txtEnfermedad = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        btnAnalizar = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblEnfermedad = new javax.swing.JTable();
        btnReporte = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        txtOracion = new javax.swing.JTextArea();
        lblEstado = new javax.swing.JLabel();
        lblTotal = new javax.swing.JLabel();
        btnCancelar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("SWATSoft - Buscar enfermedad");
        setMinimumSize(new java.awt.Dimension(970, 450));
        setResizable(false);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel2.setText("Enfermedad:");
        getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 20, -1, -1));
        getContentPane().add(txtEnfermedad, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 50, 309, 33));

        jLabel1.setText("*");
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(340, 60, -1, -1));

        btnAnalizar.setBackground(java.awt.SystemColor.controlLtHighlight);
        btnAnalizar.setFont(new java.awt.Font("Ubuntu", 1, 14));
        btnAnalizar.setForeground(new java.awt.Color(149, 184, 219));
        btnAnalizar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/swatsoft3/imagenes/lupa-icono-mini.png"))); // NOI18N
        btnAnalizar.setText("Analizar Documentos");
        btnAnalizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAnalizarActionPerformed(evt);
            }
        });
        btnAnalizar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                btnAnalizarKeyPressed(evt);
            }
        });
        getContentPane().add(btnAnalizar, new org.netbeans.lib.awtextra.AbsoluteConstraints(420, 20, -1, -1));

        tblEnfermedad.setAutoCreateRowSorter(true);
        tblEnfermedad.setModel(modelo);
        tblEnfermedad.setName("tblReporte"); // NOI18N
        tblEnfermedad.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblEnfermedad_click(evt);
            }
        });
        jScrollPane1.setViewportView(tblEnfermedad);

        getContentPane().add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 140, 920, 170));

        btnReporte.setBackground(java.awt.SystemColor.controlLtHighlight);
        btnReporte.setFont(new java.awt.Font("Ubuntu", 1, 14));
        btnReporte.setForeground(new java.awt.Color(95, 152, 180));
        btnReporte.setIcon(new javax.swing.ImageIcon(getClass().getResource("/swatsoft3/imagenes/email-man-icon.png"))); // NOI18N
        btnReporte.setText("Generar Reporte");
        btnReporte.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnReporteActionPerformed(evt);
            }
        });
        getContentPane().add(btnReporte, new org.netbeans.lib.awtextra.AbsoluteConstraints(680, 410, 240, -1));

        txtOracion.setColumns(20);
        txtOracion.setEditable(false);
        txtOracion.setRows(5);
        jScrollPane2.setViewportView(txtOracion);

        getContentPane().add(jScrollPane2, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 320, 610, 180));

        lblEstado.setText("...");
        getContentPane().add(lblEstado, new org.netbeans.lib.awtextra.AbsoluteConstraints(680, 330, -1, -1));

        lblTotal.setText("Total procesados: 0");
        getContentPane().add(lblTotal, new org.netbeans.lib.awtextra.AbsoluteConstraints(680, 370, -1, -1));

        btnCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/swatsoft3/imagenes/man-cancel.png"))); // NOI18N
        btnCancelar.setText("Cancelar");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });
        getContentPane().add(btnCancelar, new org.netbeans.lib.awtextra.AbsoluteConstraints(710, 20, 220, 60));

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void btnAnalizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAnalizarActionPerformed
// TODO add your handling code here:
    //Nuestro código AP
    //this.tblEnfermedad.getModel();
    this.lblEstado.setText("Procesando...");
    modelo.getDataVector().clear();
    ArrayList<ArrayList<String>> resultado = null;
    BE_TString error = new BE_TString();

    resultado = BL_AdministradorDeReportes.generarReporte(this.txtEnfermedad.getText(), error);

    if (resultado != null) {
//        int i = 0;

        for (ArrayList<String> aux : resultado) {
            Object[] linea = new Object[4];
            linea[0] = aux.get(0);
            linea[1] = aux.get(1);
            linea[2] = aux.get(2);
            linea[3] = aux.get(3);
            modelo.addRow(linea);
//            i++;
        }
    } else {
        if (error.getCadena().compareTo("") != 0) {
            JOptionPane.showMessageDialog(this, error.getCadena());
        }
    }
    this.lblEstado.setText("Terminado.");
    this.lblTotal.setText("Total: " + this.tblEnfermedad.getModel().getRowCount()+" resultados encontrados.");
    //this.tblEnfermedad.setModel(modelo);
    //this.tblEnfermedad.setVisible(true);
}//GEN-LAST:event_btnAnalizarActionPerformed

private void btnAnalizarKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_btnAnalizarKeyPressed
// TODO add your handling code here:
}//GEN-LAST:event_btnAnalizarKeyPressed

private void btnReporteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnReporteActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_btnReporteActionPerformed

private void tblEnfermedad_click(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblEnfermedad_click
// TODO add your handling code here:
    int aux = tblEnfermedad.getSelectedRow();
    String texto = (String)this.tblEnfermedad.getValueAt(aux, 1);
    this.txtOracion.setText(texto);
}//GEN-LAST:event_tblEnfermedad_click

private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
// TODO add your handling code here:
    this.dispose();
}//GEN-LAST:event_btnCancelarActionPerformed
    /**
     * @param args the command line arguments
     */
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAnalizar;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnReporte;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel lblEstado;
    private javax.swing.JLabel lblTotal;
    private javax.swing.JTable tblEnfermedad;
    private javax.swing.JTextField txtEnfermedad;
    private javax.swing.JTextArea txtOracion;
    // End of variables declaration//GEN-END:variables
}
